<?php

namespace app\controllers;
use Yii;
use yii\web\Controller;
class TypeclassController extends Controller
{
    // 菜品分类列表展示
    public function actionTypeclass_list()
    {
        $sql="select * from typeclass";
        $data=Yii::$app->db->createCommand($sql)->queryAll();
        return $this->renderPartial('typeclass_list',['data'=>$data]);
    }
    // 菜品类型添加页
    public function actionTypeclass_add()
    {
        return $this->renderPartial('typeclass_add');
    }

    // 菜品类型添加操作
    public function actionTypeclass_add_do()
    {
        $typeclass_name=Yii::$app->request->post('typeclass_name');

        $sql="insert into typeclass values(null,'$typeclass_name')";
        $data = Yii::$app->db->createCommand($sql)->execute();
        if($data){
            return $this->actionTypeclass_list();
        }else{
            echo "添加失败";
        }
    }
    //菜品类型删除
    public function actionTypeclass_del()
    {
        $id=Yii::$app->request->get('id');

        $sql="delete from typeclass where typeclass_id=$id";
        $data = Yii::$app->db->createCommand($sql)->execute();
        if ($data){
            return $this->actionTypeclass_list();
        }else{
            echo "删除失败";
        }
    }
}

?>